.PHONY: build run test clean help

# 默认目标
.DEFAULT_GOAL := help

# 变量定义
BINARY_NAME=data-treating
BUILD_DIR=build
MAIN_PATH=cmd/server/main.go

# 构建项目
build:
	@echo "构建项目..."
	@mkdir -p $(BUILD_DIR)
	go build -o $(BUILD_DIR)/$(BINARY_NAME) $(MAIN_PATH)
	@echo "构建完成: $(BUILD_DIR)/$(BINARY_NAME)"

# 运行服务器
run: build
	@echo "启动服务器..."
	./$(BUILD_DIR)/$(BINARY_NAME)

# 直接运行（不构建）
run-dev:
	@echo "开发模式启动服务器..."
	go run $(MAIN_PATH)

# 运行测试
test:
	@echo "运行测试..."
	go test ./...

# 运行测试客户端
test-client:
	@echo "运行测试客户端..."
	go run examples/test_client.go

# 清理构建文件
clean:
	@echo "清理构建文件..."
	rm -rf $(BUILD_DIR)
	go clean

# 安装依赖
deps:
	@echo "安装依赖..."
	go mod tidy
	go mod download

# 格式化代码
fmt:
	@echo "格式化代码..."
	go fmt ./...

# 代码检查
lint:
	@echo "代码检查..."
	golangci-lint run

# 生成API文档
docs:
	@echo "生成API文档..."
	@echo "API文档请参考 README.md"

# 帮助信息
help:
	@echo "可用的命令:"
	@echo "  build       - 构建项目"
	@echo "  run         - 构建并运行服务器"
	@echo "  run-dev     - 开发模式运行服务器"
	@echo "  test        - 运行测试"
	@echo "  test-client - 运行测试客户端"
	@echo "  clean       - 清理构建文件"
	@echo "  deps        - 安装依赖"
	@echo "  fmt         - 格式化代码"
	@echo "  lint        - 代码检查"
	@echo "  docs        - 生成文档"
	@echo "  help        - 显示帮助信息" 